package com.bamanker.authresource.controller;

import com.bamanker.cloudapi.model.response.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试接口
 *
 * @author bamanker
 */
@RestController
public class TestController {

    @GetMapping("/resource1")
    @PreAuthorize("hasAuthority('message.read')")
    public Result<String> getResource1() {
        return Result.buildSuccess("服务A -> 资源1 -> 读权限");
    }

    @GetMapping("/resource2")
    @PreAuthorize("hasAuthority('message.write')")
    public Result<String> getResource2() {
        return Result.buildSuccess("服务A -> 资源2 -> 写权限");
    }

    @GetMapping("/resource3")
    @PreAuthorize("hasAuthority('system')")
    public Result<String> resource3() {
        return Result.buildSuccess("服务A -> 资源3 -> system 权限");
    }

    @GetMapping("/api/publicResource")
    public Result<String> publicResource() {
        return Result.buildSuccess("服务A -> 公共资源");
    }

    @GetMapping("/test01")
    @PreAuthorize("hasAuthority('message.read')")
    public Result<String> test01() {
        return Result.buildSuccess("服务A -> test01 -> 读权限");
    }

    @GetMapping("/test02")
    @PreAuthorize("hasAuthority('message.write')")
    public Result<String> test02() {
        return Result.buildSuccess("服务A -> test02 -> 写权限");
    }

    @GetMapping("/app")
    @PreAuthorize("hasAuthority('app')")
    public Result<String> app() {
        return Result.buildSuccess("服务A -> app资源 -> app权限");
    }

    @GetMapping("/web")
    @PreAuthorize("hasAuthority('web')")
    public Result<String> web() {
        return Result.buildSuccess("服务A -> web资源 -> web权限");
    }

    @GetMapping("/projects")
    @PreAuthorize("hasAuthority('projects')")
    public Result<String> projects() {
        return Result.buildSuccess("服务A -> projects资源 -> projects权限");
    }

    @GetMapping("/user_info")
    @PreAuthorize("hasAuthority('user_info')")
    public Result<String> userInfo() {
        return Result.buildSuccess("服务A -> user_info资源 -> user_info权限");
    }

}